/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        def_serialport.h
 * Author:          Dan Yin
 * Date:            2022-11-23
 * Description:     the global define for serialport
 * Version:         1.0.0.0
 **********************************************************/

#ifndef DEF_FRAME_PROTOCOL_H
#define DEF_FRAME_PROTOCOL_H

#include <string.h>
#include <qmetatype.h>

// add necessary includes here
#include "def_serialport.h"

// CAN
#define DEF_MOD_ID_IAP1                     0x0100
#define DEF_MOD_ID_IAP2                     0x0200
#define DEF_MOD_ID_IAP3                     0x0300
#define DEF_MOD_ID_IAP4                     0x0400
#define DEF_MOD_ID_IAP5                     0x0500
#define DEF_MOD_ID_IAP6                     0x0600
#define DEF_MOD_ID_IAP7                     0x0700
#define DEF_MOD_ID_IAP8                     0x0800

#define DEF_MOD_ID_PCR1                     0x0010
#define DEF_MOD_ID_PCR2                     0x0020
#define DEF_MOD_ID_PCR3                     0x0030
#define DEF_MOD_ID_PCR4                     0x0040
#define DEF_MOD_ID_PCR5                     0x0050
#define DEF_MOD_ID_PCR6                     0x0060
#define DEF_MOD_ID_PCR7                     0x0070
#define DEF_MOD_ID_PCR8                     0x0080
#define DEF_MOD_ID_BROADCAST                0x00ff

#define DEF_CHANNEL_SIZE                    8
#define DEF_MIN_CAN_SIZE                    8
#define DEF_STD_CAN_SIZE                    3 * DEF_MIN_CAN_SIZE
#define DEF_PKG_CAN_HEADER1                 0x23
#define DEF_PKG_CAN_HEADER2                 0xff
#define DEF_PKG_CAN_HEADER3                 0x01
#define DEF_PKG_CAN_TAIL                    0x2a
#define DEF_PKG_CAN_INDEX1                  0x01
#define DEF_PKG_CAN_INDEX2                  0x02
#define DEF_PKG_CAN_INDEX3                  0x03

#define DEF_FUN_TEMP_FLUO                   0x01
#define DEF_FUN_SAMPLE_TEMP                 0x02
#define DEF_FUN_GET_CAN_ID                  0x04
#define DEF_FUN_SET_CAN_ID                  0x07
#define DEF_FUN_NAK                         0x15
#define DEF_FUN_ACK                         0x16
#define DEF_FUN_ENABLE_HEATING              0x1a
#define DEF_FUN_SET_HEATINT                 0x60
#define DEF_FUN_SET_DURATION                0x61
#define DEF_FUN_STARTUP_PCR                 0x63

typedef struct ST_PCR_SEND_FRAME {
    unsigned char ucFrameIdx0;
    unsigned char ucHeader1;
    unsigned char ucHeader2;
    unsigned char ucHeader3;
    unsigned char ucFunction;
    unsigned char ucValueH1;
    unsigned char ucValueL1;
    unsigned char ucValueH2;

    unsigned char ucFrameIdx1;
    unsigned char ucValueL2;
    unsigned char ucValueH3;
    unsigned char ucValueL3;
    unsigned char ucValueH4;
    unsigned char ucValueL4;
    unsigned char ucValueH5;
    unsigned char ucValueL5;

    unsigned char ucFrameIdx2;
    unsigned char ucValue1;
    unsigned char ucValue2;
    unsigned char ucValue3;
    unsigned char ucValue4;
    unsigned char ucValue5;
    unsigned char ucCRC;
    unsigned char ucTail;

    ST_PCR_SEND_FRAME() {
        memset(this, 0, sizeof(ST_PCR_SEND_FRAME));

        ucFrameIdx0 = 0x01;
        ucHeader1 = 0x23;
        ucHeader2 = 0xff;
        ucHeader3 = 0x01;
        ucFunction = 0x00;
        ucFrameIdx1 = 0x02;
        ucFrameIdx2 = 0x03;
        ucCRC = 0x00;
        ucTail = 0x2a;
    }
}PCR_SEND_FRAME;

typedef struct ST_PCR_TEMP_FLUO {
    float fTempValue1;
    float fTempValue2;
    unsigned short usRed;
    unsigned short usYellow;
    unsigned short usGreen;
    unsigned short usBlue;
    unsigned char ucD21;
    unsigned char ucD22;
    unsigned char ucD23;

    ST_PCR_TEMP_FLUO() {
        memset(this, 0, sizeof(ST_PCR_TEMP_FLUO));
    }
}PCR_TEMP_FLUO;

/*
// COM
#define DEF_MIN_PKG_SIZE                    18
#define DEF_PKG_HEADER1                     0x40
#define DEF_PKG_HEADER2                     0x4d
#define DEF_PKG_HEADER3                     0x44
#define DEF_PKG_HEADER4                     0x78
#define DEF_PKG_VERSION                     0x15
#define DEF_PKG_SOURCE_ID                   0x00

#define DEF_PKG_SYNC_SIZE                   4
#define DEF_PKG_VERSION_SIZE                1
#define DEF_PKG_MID_SIZE                    1
#define DEF_PKG_CMD_ID_SIZE                 1
#define DEF_PKG_DEST_ID_SIZE                1
#define DEF_PKG_FROM_ID_SIZE                1
#define DEF_PKG_FORMAT_SIZE                 1
#define DEF_PKG_SEQ_SIZE                    2
#define DEF_PKG_NOT_USED_SIZE               2
#define DEF_PKG_DATA_SIZE                   2
#define DEF_PKG_CRC_SIZE                    2

#define DEF_PKG_MIN_SIZE                    (DEF_PKG_SYNC_SIZE + DEF_PKG_VERSION_SIZE + (DEF_PKG_MID_SIZE + DEF_PKG_CMD_ID_SIZE) + DEF_PKG_DEST_ID_SIZE + DEF_PKG_FROM_ID_SIZE + DEF_PKG_FORMAT_SIZE + DEF_PKG_SEQ_SIZE + DEF_PKG_NOT_USED_SIZE + DEF_PKG_DATA_SIZE + 0 + DEF_PKG_CRC_SIZE)
#define DEF_PKG_FIRST_PART                  (DEF_PKG_SYNC_SIZE + DEF_PKG_VERSION_SIZE + (DEF_PKG_MID_SIZE + DEF_PKG_CMD_ID_SIZE) + DEF_PKG_DEST_ID_SIZE + DEF_PKG_FROM_ID_SIZE + DEF_PKG_FORMAT_SIZE + DEF_PKG_SEQ_SIZE + DEF_PKG_NOT_USED_SIZE + DEF_PKG_DATA_SIZE)

enum EUM_PKG_CMD_TYPE {
    E_PKG_CT_CMD,
    E_PKG_CT_DATA,
    E_PKG_CT_ACK,
    E_PKG_CT_REPLY,
    E_PKG_CT_NOTIFY
};

enum EUM_PKG_TARGET_TYPE {
    E_PKG_TT_MOTHER_BOARD,
    E_PKG_TT_MOTOR_DRIVER_BOARD,
    E_PKG_TT_PCR,
    E_PKG_TT_FLUORESCENCE,
    E_PKG_TT_HEATER,
    E_PKG_TT_ULTRASONIC,
    E_PKG_TT_BARCODE_SCANNER,
    E_PKG_TT_VIRTUAL_DEVICE,
    E_PKG_TT_UPPER_HOST
};

enum EUM_PKG_DATA_FORMAT {
    E_PKG_FMT_JSON,
    E_PKG_FMT_TEXT,
    E_PKG_FMT_BINARY
};

typedef struct ST_MIN_PKG_INFO {
    unsigned char ucHeader1;
    unsigned char ucHeader2;
    unsigned char ucHeader3;
    unsigned char ucHeader4;
    unsigned char ucVersion;
    unsigned char ucMachineID;
    unsigned char ucCommandID;
    unsigned char ucTargetID;
    unsigned char ucSourceID;
    unsigned char ucDataFormat;
    unsigned short usSequence;
    unsigned short usReserved;
    unsigned short usDataLength;
    unsigned short usPkgCRC;

    ST_MIN_PKG_INFO() {
        memset(this, 0, sizeof(ST_MIN_PKG_INFO));
    }
}MIN_PKG_INFO;

Q_DECLARE_METATYPE(ST_MIN_PKG_INFO);*/

#endif // DEF_FRAME_PROTOCOL_H
